package sketch.ast;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

import org.eclipse.jdt.core.compiler.InvalidInputException;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.parser.Scanner;
import org.eclipse.jdt.internal.compiler.parser.TerminalTokens;

import sketch.util.SketchUtil;

public class ScannerTest extends TestCase {

	public static Test suite() {
		return new TestSuite(ScannerTest.class);
	}
	
	public void testScanner() {
		Scanner scanner = new Scanner(
				true /*comment*/,
				true /*whitespace*/,
				false /*nls*/,
				ClassFileConstants.JDK1_5 /*sourceLevel*/,
				ClassFileConstants.JDK1_5 /*complianceLevel*/,
				null/*taskTag*/,
				null/*taskPriorities*/,
				true/*taskCaseSensitive*/);
		
		String sourceToParse = "ALegalIdentifier";
		char[] source = sourceToParse.toCharArray();
		scanner.setSource(source);
		final int length = source.length;
		scanner.resetTo(0, length - 1);
		try {
			int tokenType = scanner.scanIdentifier();
			SketchUtil.stdln(tokenType);
			if (tokenType != TerminalTokens.TokenNameIdentifier) {
				throw new IllegalArgumentException();
			}
			if (scanner.currentPosition != length) {
				// this is the case when there is only one identifier see 87849
				throw new IllegalArgumentException();
			}
		} catch(InvalidInputException e) {
			throw new IllegalArgumentException();
		}
	}
	
}
